
/*
 * @Author: qsy
 * @Date: 2024-07-23 14:44:24
 * @LastEditors: qsy
 * @LastEditTime: 2025-04-09 21:06:58
 * @Description: mqtt头文件
 */

// 头文件格式
#ifndef MY_MQTT_H
#define MY_MQTT_H

#include <stdio.h>
#include <stdint.h>
#include <stddef.h>
#include <string.h>
#include "esp_system.h"
#include "nvs_flash.h"
#include "esp_event.h"
#include "esp_netif.h"
// #include "protocol_examples_common.h"

#include "esp_log.h"
#include "mqtt_client.h"
#include "esp_tls.h"
// #include "esp_ota_ops.h"
#include <sys/param.h>
#include <driver/gpio.h>
#include <cJSON.h>
#include "wifi_connect.h"
#include "my_adc.h"


#define URL_TEST "mqtt://mqtts.heclouds.com:1883"
#define MQTT_PORT 1883 // 端口


#define DEVICE_ID "device1" // 设备ID
#define MQTT_SUB_TOPIC "$sys/3CqoyHWbCK/device/thing/property/post/reply" // 订阅主题
#define MQTT_PUB_TOPIC "$sys/3CqoyHWbCK/device/thing/property/post" // 发布主题

// $sys/3CqoyHWbCK/device/thing/event/post
// 发送事件的主题
#define MQTT_EVENT_TOPIC "$sys/3CqoyHWbCK/device/thing/event/post"
// 发送事件的主题
#define MQTT_EVENT_TOPIC_LEN "$sys/3CqoyHWbCK/device/thing/event/post/reply"

// 用户名 
#define MQTT_USER "3CqoyHWbCK"
// 密码
#define MQTT_PASS "version=2018-10-31&res=products%2F3CqoyHWbCK%2Fdevices%2Fdevice&et=2810295937&method=md5&sign=MnrZghwMu4BODMCPipYeEw%3D%3D"


extern esp_mqtt_client_handle_t client;

void mqtt_app_start(void); // 启动mqtt
// void mtqq_start(void); // 测试
void mqtt_app_stop(void);

void mqtt_send_warning_event(uint8_t warn_para); // 发送警告事件


void mqtt_data_upload(my_value_t my_value); // 上传数据到mqtt

void mqtt_send_manual_event(bool m_or_a); // 发送手动事件

#endif